home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / Thread Manager Extension 2.0.1 / Sample Applications / Power Examples / SortPicts / Source / Windows.cp < prev   
Encoding:
Text File  |  1994-06-03  |  6.5 KB  |  221 lines  |  [TEXT/MPS ]

  1. /*************************************************************************************
  2.  *
  3.  *    Object Oriented Shell
  4.  *
  5.  *    Events.C
  6.  *
  7.  *      Copyright © Apple Computer, Inc. 1988 - 1993
  8.  *      All rights reserved.
  9.  *
  10.  *    This file contains the code to interfrace directly to your WindowObj.
  11.  *    This will perform certain rudimentary functions for windows in general,
  12.  *    all window specific functionality will be handled by your Obj or by WindowObj.
  13.  *
  14.  *************************************************************************************/
  15.  
  16. #include "main.h"
  17. #include <Traps.h>
  18. #include "WindowObj.h"
  19. #include <Strings.h>
  20.  
  21.  
  22. /**************************************************************************************
  23.  
  24.     CloseAnyWindow
  25.     
  26.     Close the given window in a manner appropriate for that window.  If the
  27.     window belongs to a DA, we call CloseDeskAcc.  For dialogs, we simply hide
  28.     the window.  If we had any document windows, we would probably call either 
  29.     DisposeWindow or CloseWindow after disposing of any docuemtn data and/or
  30.     controls.
  31.     
  32. ***************************************************************************************/
  33. Boolean    CloseAnyWindow(WindowPtr window)
  34. {
  35.     if( IsDAWindow(window))
  36.     {
  37.         CloseDeskAcc( ( (WindowPeek) window)->windowKind);
  38.         return true;
  39.     }
  40.     else if(IsDialogWindow(window))
  41.     {
  42.         HideWindow(window);
  43.         return true;
  44.     }
  45.     else if(IsAppWindow(window))
  46.     {
  47.         if(window == ToWindowObj(window)->me)
  48.         {
  49.             return (ToWindowObj(window)->CloseWindowObj());
  50.         }
  51.         else
  52.         {
  53.             DisposeWindow( window);
  54.             return true;
  55.         }
  56.     }
  57.     else                //  Wasn't any of the above windows... 
  58.         return false;    //  I couldn't close it...
  59. }
  60.  
  61.  
  62. /**************************************************************************************
  63.  
  64.     CloseAllAppWindows
  65.     
  66.     This routine will close all application windows.  Its function is mostly for
  67.     object windows which need to close all the application windows.
  68.     It's also used by the quit code.
  69.     
  70. ***************************************************************************************/
  71. Boolean    CloseAllAppWindows( void)
  72. {
  73.     WindowPtr    window;
  74.     Boolean        closeFlag = false;
  75.     
  76.     while( (window = FrontWindow()) != nil)
  77.         closeFlag &= CloseAnyWindow( window);
  78.     return closeFlag;
  79. }
  80.  
  81. /**************************************************************************************
  82.  
  83.     AppConvertScrap
  84.     
  85.     This code converts scraps to the DeskScrap.
  86.     The catch is that there isn't anything the standard application can do.
  87.     The reason is that there is no TextEditRecord and there are no open windows.
  88.     Hopefully windows are cogniscent enough to handle their data correctly.
  89.     
  90. ***************************************************************************************/
  91. void    AppConvertScrap()
  92. {
  93.     //    I do nothing.  I suggest you do nothing.
  94.     //  But, obviously the hook has been installed.
  95. }
  96.  
  97. /**************************************************************************************
  98.  
  99.     DeathAlertStr
  100.     
  101.     Display an alert that tells the user an error occurred, then exits the
  102.     program.  This routine is used as an ultimate bail-out for serious errors
  103.     that bprohibit the continuation of the application.  The error string is
  104.     used so that a relevant message can be displayed.
  105.     
  106. ***************************************************************************************/
  107. void    DeathAlertStr(char *string)
  108. {
  109.     short        itemHit;
  110.     Str255        theMessage;
  111.     
  112.     SetCursor( &qd.arrow);
  113.     c2pstr( string);
  114.     ParamText(theMessage, NIL, NIL, NIL);
  115.     SetCursor( &qd.arrow);
  116.     itemHit = StopAlert(rErrorAlert, NIL);
  117.     ExitToShell();
  118. }
  119.  
  120.  
  121. /**************************************************************************************
  122.  
  123.     DeathAlertStrErr
  124.     
  125.     Display an alert that tells the user an error occurred and report the error.
  126.     Then exits the program.  This routine is used as an ultimate bail-out for 
  127.     serious errors that bprohibit the continuation of the application.  
  128.     The error string is used so that a relevant message can be displayed.
  129.     
  130. ***************************************************************************************/
  131. void    DeathAlertStrErr(char *string, OSErr errorCode)
  132. {
  133.     short        itemHit;
  134.     Str255        theMessage;
  135.     Str255        errString;
  136.     
  137.     SetCursor( &qd.arrow);
  138.     c2pstr( string);
  139.     NumToString( errorCode, errString);
  140.     ParamText(theMessage, errString, NIL, NIL);
  141.     SetCursor( &qd.arrow);
  142.     itemHit = StopAlert(rErrorAlert, NIL);
  143.     ExitToShell();
  144. }
  145.  
  146.  
  147. /**************************************************************************************
  148.  
  149.     IsAppWindow
  150.     
  151.     Check to see if a window belongs to the application.  If the window pointer
  152.     passed was NIL, then it could not be an application window.  WindowKinds
  153.     that are negative belong to the sytem and wndowKinds less than userKind 
  154.     are reserved by Apple except for windowKinds equal to dialogKind, which
  155.     mean it is a dialog.
  156.     
  157. ***************************************************************************************/
  158. Boolean    IsAppWindow(WindowPtr window)
  159. {
  160.     if(window == NIL)
  161.         return false;
  162.     else
  163.         return ((WindowPeek)window)->windowKind == WindowObjKind;
  164. }
  165.  
  166. /**************************************************************************************
  167.  
  168.     IsDAWindow
  169.     
  170.     Check to see if a window belongs to a desk accessory.  It belongs to a DA
  171.     if the windowKind field of the widnow record is negative.
  172.     
  173. ***************************************************************************************/
  174. Boolean    IsDAWindow(WindowPtr window)
  175. {
  176.     if( window == NIL)
  177.         return false;
  178.     else
  179.         return ( ( (WindowPeek)window)->windowKind < 0);
  180. }
  181.  
  182. /**************************************************************************************
  183.  
  184.     IsDialogWindow
  185.     
  186.     Check to see if a window belongs is a dialog window.  We can determine this by
  187.     checking to see if the windowKind field is equal to dialogKind.
  188.     
  189. ***************************************************************************************/
  190. Boolean    IsDialogWindow(WindowPtr window)
  191. {
  192.     if( window == NIL)
  193.         return false;
  194.     else
  195.         return( ( (WindowPeek)window)->windowKind == dialogKind);
  196. }
  197.  
  198. /**************************************************************************************
  199.  
  200.     InvalidateScrollbars
  201.     
  202.     Call InvalRect on the right and bottom edges of a window.  This routine is
  203.     called during the resizing of a window to take care of the scroll bar lines
  204.     and grow icon.
  205.     
  206. ***************************************************************************************/
  207. void    InvalidateScrollbars(WindowPtr theWindow)
  208. {
  209.     Rect    tempRect;
  210.     
  211.     SetPort( theWindow);
  212.     tempRect = theWindow->portRect;
  213.     tempRect.left = tempRect.right - 15;
  214.     InvalRect(&tempRect);
  215.     EraseRect(&tempRect);
  216.     tempRect = theWindow->portRect;
  217.     tempRect.top = tempRect.bottom - 15;
  218.     InvalRect( &tempRect);
  219.     EraseRect( &tempRect);
  220. }
  221.